<template>
    <div class="main">
      <ul class="list-do">
        <li v-for="item in list" :key="item.id" :class="{ completed: item.isdo }">
          <input class="input-item" type="checkbox" v-model="item.isdo" :id="'input-' + item.id" />
          <label :for="'input-' + item.id">{{ item.name }}</label>
          <button class="destroy" @click="delTo(item.id)"></button>
        </li>
      </ul>
    </div>
</template>

<script setup>
// 从vue库中导入defineProps和defineEmits函数
import { defineProps, defineEmits } from 'vue'
// 定义组件接收的属性，这里接收待办事项列表
const props = defineProps(['list'])

// 定义组件触发的自定义事件，这里触发删除待办事项的事件
const emit = defineEmits(['delTodo'])
// 删除待办事项的方法
const delTo = (id) => {
  // 如果id存在,则触发delTodo事件并传递id。先判断id的值,如果id是一个有效的值,那么会执行 && 后面的表达式；如果id是“假值”,不会执行后面的内容
  emit('delTodo', id) 
}
</script>
<style>
.main {
    position: relative;
    z-index: 2;
    border-top: none;
    padding: 25px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.list-do {
    margin: 0;
    padding: 0;
    list-style: none;
}

.list-do li {
    position: relative;
    font-size: 20px;
    border-bottom: 1px solid #eee;
    padding: 20px;
    margin-bottom: 12px;
    background-color: #f9f9f9;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: background-color 0.3s;
}

.list-do li:last-child {
    border-bottom: none;
}

.list-do li:hover {
    background-color: #f0f0f0;
}

.list-do li .input-item {
    text-align: center;
    width: 30px;
    height: auto;
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto 0;
    border: none;
    opacity: 0;
}

.list-do li .input-item+label {
    background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23949494%22%20stroke-width%3D%223%22/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center left;
    padding-left: 45px;
}

.list-do li .input-item:checked+label {
    background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%2359A193%22%20stroke-width%3D%223%22%2F%3E%3Cpath%20fill%3D%22%233EA390%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22%2F%3E%3C%2Fsvg%3E");
}

.list-do li label {
    word-break: break-all;
    display: block;
    line-height: 1.3;
    transition: color 0.4s;
    font-weight: 400;
    color: #333;
}

.list-do li.completed label {
    color: #949494;
    text-decoration: line-through;
}

.list-do li .destroy {
    position: absolute;
    top: 0;
    right: 15px;
    bottom: 0;
    width: 40px;
    height: 40px;
    margin: auto 0;
    font-size: 32px;
    transition: color 0.2s ease-out;
    border: none;
    background-color: transparent;
    color: #c18585;
    opacity: 0;
    transition: opacity 0.3s;
}

.list-do li:hover .destroy {
    opacity: 1;
}

.list-do li .destroy:hover,
.list-do li .destroy:focus {
    color: #ff6b6b;
}

.list-do li .destroy:after {
    content: "×";
    display: block;
    height: 100%;
    line-height: 1.1;
}
</style>